<?php

set_time_limit(0);

include 'library.php';
$addr = address();

//Database connection
include 'mysql_connect.inc';

for($x=0;$x<200001;$x++){
	if($x % 6 == 0){
		$m_member_type = 'NGO';
	}else if($x % 3 == 0){
		$m_member_type = 'BUS';
	}else if($x % 2 == 0){
		$m_member_type = 'IND';
	}else{
		$m_member_type = 'NGO';
	}
	
	$rand = rand(1,100);
	$m_user_id = rand(100000,999999);
	switch(TRUE){
		case ($rand < 10):
			if($rand < 5){
				$name = 'Projector '.$rand;
				$tag_array = array('Kodak','computers','Vista');
			}else{
				$name = 'Car '.$rand;
				$tag_array = array('Honda','car');
			}
			break;
		case ($rand < 20):
			if($rand < 15){
				$name = 'Board Games '.$rand;
				$tag_array = array('toys','games','Hasbro');
			}else{
				$name = 'Gateway '.$rand;
				$tag_array = array('computers');
			}
			break;
		case ($rand < 40):
			if($rand < 30){
				$name = 'Fax Machine '.$rand;
				$tag_array = array('Hewlett Packard','HP','car');
			}else{
				$name = 'Scanner '.$rand;
				$tag_array = array('Canon','scanner','office supplies');
			}
			break;
		case ($rand < 60):
			if($rand < 50){
				$name = 'HP '.$rand;
				$tag_array = array('HP','printer','laser printer');
			}else{
				$name = 'Inkjet '.$rand;
				$tag_array = array('printer','inkjet');
			}
			break;
		case ($rand < 101):
			if($rand < 80){
				$name = 'Dell '.$rand;
				$tag_array = array('PC','computers','Vista');
			}else{
				$name = 'Macintosh '.$rand;
				$tag_array = array('MAC','computers','Leopard');
			}
			break;
	}

	switch(TRUE){
		case ($rand < 10):
			$description = "This is a good $name. It's in ok condition.";	
			break;
		case ($rand < 20):
			$description = "This is a good $name. It's in great condition.";
			break;
		case ($rand < 30):
			$description = "This is an item I am willing to donate.";
			break;
		case ($rand < 40):
			$description = "This is a good $name. It's in great condition.";
			break;
		case ($rand < 50):
			$description = "Kind of broken but ok.";
			break;
		case ($rand < 60):
			$description = "Hewlett Packard made this.";
			break;
		case ($rand < 70):
			$description = "Installed with Vista.";
			break;
		case ($rand < 80):
			$description = "$name has XP on it.";
			break;
		case ($rand < 90):
			$description = "These have college applications installed on them.";
			break;
		case ($rand < 100):
			$description = "Only been used once.";
			break;
	}
	
	// Insert item into item table
	$name_id = $name.rand(1,9999);
	$item_id = make_unique_id($name_id);
			$query = mysql_query("INSERT INTO items VALUES('','$item_id','$m_user_id','$m_member_type','$name','$description','$image_name')");
	
	$arr_size = count($tag_array);
	
	// Go through tag array and
	// add tags if they don't exist
	// also, create tagmap
	for($y = 0;$y < $arr_size; $y++){
		$tag_name = $tag_array["$y"];
		$tag_exists = mysql_num_rows(mysql_query("SELECT * FROM tags WHERE name='$tag_name'"));
		
		$tag_id = make_unique_id($tag_name);
			
		// If tag is not in tag table,
		// insert it
		if(!$tag_exists){
			$query = mysql_query("INSERT INTO tags VALUES('$tag_id','$tag_name')");
		}
		
		$tag_map_exists = mysql_num_rows(mysql_query("SELECT * FROM tagmap WHERE tag_id='$tag_id' AND item_id='$item_id'"));
		
		// If tagmap is not the in the table
		// create tagmap for the new item
		if(!$tag_map_exists){
			$query = mysql_query("INSERT INTO tagmap VALUES('','$tag_id','$item_id')");
		}
	}
}	
?>